home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.output.*;
- import sub_arctic.input.*;
-
- /**
- * This class implements a scale -- a horizontal scrollbar with no
- * buttons on the ends and a fixed size thumb. It uses the style
- * system for its display.
- *
- * @author Ian Smith
- */
-
- public class scale extends h_slider {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor for a scale.
- * @param int xv x position.
- * @param int yv y position.
- * @param int wv width in pixels.
- * @param int minv minimum slider value.
- * @param int maxv maximum slider value.
- * @param int init_val initial slider value.
- * @param int lincv large increment value (the user clicks in the thumb
- * area but not on the thumb).
- * @param callback_object obj the object which receives the callbacks.
- */
- public scale(int xv, int yv, int wv, int minv, int maxv, int init_val,
- int lincv,callback_object obj) {
-
- super(xv,yv,wv,minv,maxv,init_val,0 /* doesn't matter */,lincv,obj);
-
- /* normally, user's of the style system don't want boxed */
- set_boxed(false);
-
- /* now build the images ... */
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Constructor for a scale which assumes you will position it either
- * directly or with constraints.
- *
- * @param int wv width in pixels.
- * @param int minv minimum slider value.
- * @param int maxv maximum slider value.
- * @param int init_val initial slider value.
- * @param int lincv large increment value (the user clicks in the thumb
- * area but not on the thumb).
- * @param callback_object obj the object which receives the callbacks.
- */
- public scale(int wv, int minv, int maxv, int init_val,
- int lincv,callback_object obj) {
-
- super(0,0,wv,minv,maxv,init_val,0 /* doesn't matter */,lincv,obj);
-
- /* normally, user's of the style system don't want boxed */
- set_boxed(false);
-
- /* now build the images ... */
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Constructor for a scale with some reasonable defaults. We default
- * the initial value to the minimum value and the large increment
- * to 1/4 of the range of the scale. We assume you will use constraints
- * or directly set the position of this object.
- *
- * @param int wv width in pixels
- * @param int minv minimum slider value
- * @param int maxv maximum slider value
- * @param callback_object obj the object which receives the callbacks.
- */
- public scale(int wv, int minv, int maxv,callback_object obj) {
-
- super(0,0,wv,minv,maxv,minv,0 /* doesn't matter */,(maxv-minv)/4,obj);
-
- /* normally, user's of the style system don't want boxed */
- set_boxed(false);
-
- /* now build the images ... */
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function is called to create the appearance of the scale.
- */
- public void style_changed() {
-
- /* make the images */
- style cs=style_manager.current_style();
- loaded_image back,thumb;
- back=cs.scale_background(w());
- set_back_img(back);
- thumb=cs.scale_thumb();
- set_thumb_img(thumb);
-
- set_intrinsic_h(cs.scale_height());
-
- set_thumb_shift(cs.scale_thumb_shift());
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override the drawing code in h_slider_display to allow us to not
- * have the end pieces of the scrollbar.
- *
- * @param drawable d the drawing surface to put the image on.
- */
- public void draw_self_local(drawable d) {
- int off;
- int shift=style_manager.current_style().scale_unusable_width();
-
- d.tileImage(_back_img,0,0,w(),h());
-
- /* compute offset for thumb */
- off = thumb_offset();
-
- /* draw the thumb if we have room for one */
- if (off >= 0) {
- d.drawImage(_thumb_img, off + shift, thumb_shift());
- }
-
- /* draw a box around the whole thing if that flag is set
- * (which it is by default) */
- if (boxed()) {
- d.setColor(style_manager.default_color_scheme().foreground());
- d.drawRect(0,0, w()-1,h()-1);
- }
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * We override the function that computes the offset of the thumb
- * to ignore the areas that normally would be used for the end pieces.
- *
- * @return int the amount the thumb should be shifted right to account for
- * the value of the scale.
- */
- protected int thumb_offset() {
- int off, slide_range, value_range;
-
- /* compute ranges for thumb */
- slide_range = w() - _thumb_img.width() -
- (2*style_manager.current_style().scale_unusable_width());
- value_range = max_val() - min_val();
-
- /* return negative if there is no room for the thumb */
- if (slide_range <= 0 || value_range <= 0) return -1;
-
- /* otherwise compute drawing offset for thumb */
- off = (value() - min_val()) * slide_range / value_range;
- if (off < 0) off = 0;
- if (off > slide_range) off = slide_range;
- return off;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override the press behavior to avoid the system getting confused
- * about us not having the end pieces.
- *
- * @param event evt the press event (mouse down).
- * @param Object user_info the information that was handed to the
- * pick_collector when this object was deemed to be
- * picked (this value is given to the drag focus
- * agent also, so it will be propagated along to the
- * drag calls below).
- * @return boolean true if we consumed this event, which we will.
- */
- public boolean press(event evt, Object user_info) {
- int off;
-
- /* compute the offset to the thumb */
- off = thumb_offset();
-
- /* if there is no thumb, bail out now */
- if (off < 0) return false;
-
- /* before thumb? */
- if (evt.local_x() < off) {
- /* do a large negative increment */
- set_value(value() - large_inc());
-
- /* do callback */
- dynamic_callback(evt);
- static_callback(evt);
- return true;
- }
-
- /* in the thumb? */
- if (evt.local_x() < off+_thumb_img.width()) {
- /* make us the drag focus to track the thumb */
- manager.simple_drag_focus.set_focus_to(this,evt,new int_holder());
- return true;
- }
-
- /* must be below the thumb, do a large positive increment */
- set_value(value() + large_inc());
-
- /* do callback */
- dynamic_callback(evt);
- static_callback(evt);
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Start of a drag for the thumb. Override to avoid the calculation
- * for the left image.
- *
- * @param event evt the event that is starting the drag (usually a press)
- * @param Object user_info the object passed to the simple drag_agent
- */
- public boolean drag_start(event evt, Object user_info) {
- int off;
-
- /* remember how far away from top of thumb the event is */
- off = thumb_offset();
- ((int_holder)user_info).value = evt.local_x() - off;
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Movement within a drag of the thumb. Overridden to avoid the
- * calculations involving the end pieces.
- *
- * @param event evt the drag event (mouse move).
- * @param Object user_info the object passed to the simple drag_agent.
- */
- public boolean drag_feedback(event evt, Object user_info) {
- int off, slide_range;
- int value_range, old_value;
-
- /* hold on to old value for a second */
- old_value = value();
-
- /* determine new top of thumb */
- off = evt.local_x() - ((int_holder)user_info).value;
-
- /* determine new value from this */
- slide_range = w() - _thumb_img.width() -
- (2*style_manager.current_style().scale_unusable_width());
-
- value_range = max_val() - min_val();
- set_value(min_val() + (off * value_range)/slide_range);
-
- /* if this is a new value, cause a redraw of us and do the callback */
- if (value() != old_value) {
- dynamic_callback(evt);
- }
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-